package com.example.demo.bean;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Created by czc-pual on 2019/1/5.
 */
@Configuration
public class AppConfig {
    @Bean(initMethod = "init")
    public Foo foo() {
        return new Foo(bar());
    }
    @Bean(destroyMethod = "cleanup")
    public Bar bar() {
        return new Bar();
    }

}
//生命周期回调
class Foo {
    public Foo(Bar bar) {
        System.out.println("bar:"+bar);
    }

    public void init() {
        System.out.println("init()");
    }
}
class Bar {
    public void cleanup() {
        System.out.println("cleanup()");
    }
}
